<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="所在城市">
        <el-select v-model="form.region" placeholder="请选择活动区域">
          <el-option label="上海" value="上海"></el-option>
          <el-option label="北京" value="北京"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="年龄*">
        <el-input v-model="form.age"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: "",
        age:'',
        region: "",
        type: [],
      },
     cityData:[]
    };
  },
  methods: {
    onSubmit() {
    //   console.log("submit!");
        if( this.form.name == '' || this.form.age == '' || this.region == '' ) {
            return alert('内容不能为空')
        }
        let obj = {
            city: this.form.region,
            title: this.form.name,
            age: this.form.age,
            flag: false
        }
        this.cityData.push(obj)
        this.setCity()
        this.$emit('sonData',this.cityData)
        // 清空
        this.form={
            name:'',
            age:'',
            regin:''
        }
    },
    setCity() {
        localStorage.setItem('city',JSON.stringify(this.cityData))
    }
  },
  mounted() {
    
  },
};
</script>

<style lang="scss">
</style>